from django.conf import settings
from django.core.urlresolvers import resolve

class MenuBuildError(Exception):
	"""Failed to build menu"""

class Menu(object):
	"""Represents one menu"""
	def __init__(self,text="",href=None,title=None):
		"""Inits Menu
		text -- text visible on page
		href -- page, to which link leads to
		title -- title of link"""
		self.subs = []
		self.name = Item(text,href,title)

	def add_sub(self,sub):
		"""Adds submenu to menu"""
		self.subs.append(sub)

class SubMenu(object):
	"""SubMenu represents link in menu, can have list of links, presented on page with caption"""
	def __init__(self,text="",href=None,title=None):
		"""Inits SubMenu
		text -- text visible on page
		href -- page, to which link leads to
		title -- title of link"""

		self.name = Item(text,href,title)
		self.items = []
	def add_item(self,item):
		"""Adds item to submenu"""
		self.items.append(item)

class Item(object):
	"""Item represents one link or title"""
	def __init__(self,text="",href=None,title=None):
		"""Inits Item
		text -- text visible on page
		href -- page, to which link leads to
		title -- title of link"""
		self.text = text
		self.href = href
		self.title = title

def get_mod_func(callback):
	dot = callback.rindex('.')
	return callback[:dot], callback[dot+1:]
